<%--
  Created by IntelliJ IDEA.
  User: lichengming
  Date: 2017/8/3
  Time: 上午7:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/resources.jsp" %>
<html>
<head>
    <title>区县代理</title>
</head>
<body>
<div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">查询条件</h3>
        </div>
        <div class="panel-body">
            <form class="form-inline">
                <div class="form-group">
                    <input type="text" class="form-control" id="searchRealName" name="real_name" placeholder="姓名">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" id="searchPhone" name="phone" placeholder="手机号">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" id="searchAddress" name="address" placeholder="地址">
                </div>
                <button type="button" class="btn btn-info btn-search">查询</button>
                <button type="button" class="btn btn-default btn-reset">清空</button>
            </form>
        </div>
    </div>
</div>

<div class="ems_table_content">
    <div class="panel panel-default">
        <div class="panel-heading">区县代理列表</div>
        <div id="table_tools">
            <div class="form-inline" role="form">
                <button type="button" id="area_agent_add" class="btn btn-outline btn-success">
                    <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
                    添加
                </button>
                <button type="button" id="area_agent_edit" class="btn btn-outline btn-primary">
                    <i class="glyphicon glyphicon-edit" aria-hidden="true"></i>
                    修改
                </button>
                <button type="button" id="area_agent_delete" class="btn btn-outline btn-danger">
                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                    删除
                </button>
                <button type="button" id="area_agent_active" class="btn btn-outline btn-warning">
                    <i class="glyphicon glyphicon-edit" aria-hidden="true"></i>
                    激活
                </button>
                <button type="button" id="area_agent_freeze" class="btn btn-outline btn-default">
                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                    冻结
                </button>
            </div>
        </div>
        <table id="areaAgentTable"
               data-url="/ems/areaagent/pagination"
               data-show-export="true">
            <thead>
            <tr>
                <th data-field="state" data-checkbox="true"></th>
                <th data-field="real_name">姓名</th>
                <th data-field="phone">手机号</th>
                <th data-field="pay_amount">缴纳费用</th>
                <th data-field="address">地址</th>
                <th data-field="status" data-formatter="statusFormat">状态</th>
            </tr>
            </thead>
        </table>
    </div>
    <script>
        function statusFormat(srcValue) {

            if (srcValue == 1) {
                return "<span style='color: #3cb371;font-weight: bold' >代理中</span>";
            }else {
                return "<span style='color: red;font-weight: bold'>未代理</span>";
            }
        }
    </script>
</div>
<script>
    $(function () {
        $("#areaAgentTable").createTable();

        //添加
        $("#area_agent_add").on("click",function () {
           window.location.href = "/ems/areaagent/edit"
        });

        //编辑
        $("#area_agent_edit").on("click",function () {
            var selectRows =  $('#areaAgentTable').bootstrapTable('getSelections');
            if (selectRows.length == 0) {
                $.errorAlert("请选择要编辑的数据");
                return;
            }
            if (selectRows.length > 1) {
                $.errorAlert("暂时不支持多行数据编辑");
                return;
            }
            window.location.href = "/ems/areaagent/edit?id=" + selectRows[0].id;
        })

        //删除
        $("#area_agent_delete").on("click",function () {
            var selectRows =  $('#areaAgentTable').bootstrapTable('getSelections');
            if (selectRows.length == 0) {
                $.errorAlert("请选择要删除的数据");
                return;
            }

            var areaAgentIdList = "";
            for (var i = 0;i<selectRows.length;i++) {
                areaAgentIdList += selectRows[i].id + ",";
            }
            areaAgentIdList = areaAgentIdList.substring(0,areaAgentIdList.length - 1);
            $.confirmAlert("你确定要删除这些数据吗",function(){
                $.emsAjax({
                    data:{areaAgentIdList:areaAgentIdList},
                    type:"POST",
                    url:"/ems/areaagent/delete",
                    success:function(resp) {
                        if (resp.status == "000") {
                            $.alert(resp.message);
                            search("#areaAgentTable",getQueryParams());
                        }else {
                            $.errorAlert(resp.message);
                        }
                    }
                });
            });
        });

        //激活
        $("#area_agent_active").on("click",function () {
            var selectRows =  $('#areaAgentTable').bootstrapTable('getSelections');
            if (selectRows.length == 0) {
                $.errorAlert("请选择要激活的记录");
                return;
            }

            if (selectRows.length > 1) {
                $.errorAlert("暂时不支持多行数据编辑");
                return;
            }

            $.confirmAlert("你确定要激活该记录吗",function(){
                $.emsAjax({
                    data:{id:selectRows[0].id},
                    type:"POST",
                    url:"/ems/areaagent/activate",
                    success:function(resp) {
                        if (resp.status == "000") {
                            $.alert(resp.message);
                            search("#areaAgentTable",getQueryParams());
                        }else {
                            $.errorAlert(resp.message);
                        }
                    }
                });
            });
        });

        //冻结
        $("#area_agent_freeze").on("click",function () {
            var selectRows =  $('#areaAgentTable').bootstrapTable('getSelections');
            if (selectRows.length == 0) {
                $.errorAlert("请选择要冻结的记录");
                return;
            }

            if (selectRows.length > 1) {
                $.errorAlert("暂时不支持多行记录的冻结");
                return;
            }

            $.confirmAlert("你确定要冻结该记录吗",function(){
                $.emsAjax({
                    data:{id:selectRows[0].id},
                    type:"POST",
                    url:"/ems/areaagent/freeze",
                    success:function(resp) {
                        if (resp.status == "000") {
                            $.alert(resp.message);
                            search("#areaAgentTable",getQueryParams());
                        }else {
                            $.errorAlert(resp.message);
                        }
                    }
                });
            });
        });
    });
</script>
</body>
</html>
